define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'buy/house/index' + location.search,
                    add_url: 'buy/house/add',
                    edit_url: 'buy/house/edit',
                    del_url: 'buy/house/del',
                    multi_url: 'buy/house/multi',
                    import_url: 'buy/house/import',
                    table: 'buy_house',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'sales_representative', title: __('Sales_representative'), operate: 'LIKE'},
                        {field: 'date_of_visit', title: __('Date_of_visit'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'sex_data', title: __('Sex_data'), searchList: {"male":__('Sex_data male'),"female":__('Sex_data female')}, formatter: Table.api.formatter.normal},
                        {field: 'contact', title: __('Contact'), operate: 'LIKE'},
                        {field: 'required_area', title: __('Required_area')},
                        {field: 'position_data', title: __('Position_data'), searchList: {"new_area":__('Position_data new_area'),"old_area":__('Position_data old_area'),"new_and_old":__('Position_data new_and_old')}, formatter: Table.api.formatter.normal},
                        {field: 'look_at_the_community', title: __('Look_at_the_community'), operate: 'LIKE'},
                        {field: 'architectural_style_data', title: __('Architectural_style_data'), searchList: {"like":__('Architectural_style_data like'),"commonly":__('Architectural_style_data commonly'),"dislike":__('Architectural_style_data dislike')}, formatter: Table.api.formatter.normal},
                        {field: 'architectural_form_data', title: __('Architectural_form_data'), searchList: {"high_level":__('Architectural_form_data high_level'),"multi_storey":__('Architectural_form_data multi_storey'),"villa":__('Architectural_form_data villa')}, formatter: Table.api.formatter.normal},
                        {field: 'gardens_data', title: __('Gardens_data'), searchList: {"like":__('Gardens_data like'),"commonly":__('Gardens_data commonly'),"dislike":__('Gardens_data dislike')}, formatter: Table.api.formatter.normal},
                        {field: 'garage_num_data', title: __('Garage_num_data'), searchList: {"garage":__('Garage_num_data garage'),"not_garage":__('Garage_num_data not_garage')}, formatter: Table.api.formatter.normal},
                        {field: 'price_willingness', title: __('Price_willingness'), operate: 'LIKE'},
                        {field: 'real_estate_cycle_data', title: __('Real_estate_cycle_data'), searchList: {"1":__('Real_estate_cycle_data 1'),"3":__('Real_estate_cycle_data 3'),"6":__('Real_estate_cycle_data 6'),"12":__('Real_estate_cycle_data 12')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_method_data', title: __('Pay_method_data'), searchList: {"1":__('Pay_method_data 1'),"2":__('Pay_method_data 2'),"3":__('Pay_method_data 3'),"4":__('Pay_method_data 4'),"5":__('Pay_method_data 5')}, formatter: Table.api.formatter.normal},
                        {field: 'visiting_route_data', title: __('Visiting_route_data'), searchList: {"1":__('Visiting_route_data 1'),"2":__('Visiting_route_data 2'),"3":__('Visiting_route_data 3'),"4":__('Visiting_route_data 4'),"5":__('Visiting_route_data 5'),"6":__('Visiting_route_data 6'),"7":__('Visiting_route_data 7'),"8":__('Visiting_route_data 8'),"9":__('Visiting_route_data 9'),"10":__('Visiting_route_data 10'),"11":__('Visiting_route_data 11')}, formatter: Table.api.formatter.normal},
                        {field: 'make_num', title: __('Make_num')},
                        {field: 'purchase_demand_data', title: __('Purchase_demand_data'), searchList: {"1":__('Purchase_demand_data 1'),"2":__('Purchase_demand_data 2'),"3":__('Purchase_demand_data 3'),"4":__('Purchase_demand_data 4'),"5":__('Purchase_demand_data 5')}, formatter: Table.api.formatter.normal},
                        {field: 'entangled_reasons', title: __('Entangled_reasons'), operate: 'LIKE'},
                        {field: 'watch_status', title: __('Watch_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
